﻿@inherits BlazorLayoutComponent
@inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper

<div class="sidebar">
    <NavMenu />
</div>

<div class="main">
    <div class="top-row px-4">
       
        <div id="unlogin" class="text-right">
            <NavLink class="btn btn-primary" href="/login" Match=NavLinkMatch.All>
                <span class="oi oi-user" aria-hidden="true"></span> 登录
            </NavLink>
            <NavLink class="btn btn-default" href="/regiter" Match=NavLinkMatch.All>
                <span class="oi oi-user" aria-hidden="true"></span> 注册
            </NavLink>
        </div>
      
            <div id="logined"  class="text-right">
                <span class="hello">您好，<strong id="spanUsername">@Username</strong></span>
                <button class="btn btn-default" onclick="@Logout">注销</button>
            </div>
      
            </div>

            <div class="content px-4">
                @Body
            </div>
        </div>
@functions {
    public string Username { get; set; }
    public string Token { get; set; }
    // public string token = string.Empty;

    protected override void OnInit()
    {
        // Token = JsInterop.GetToken();
        Username = JsInterop.GetUsername();
        //JsInterop.SetHeaderStatus();
        // RegisteredFunction.Invoke<bool>("log", "测试");
        base.OnInit();
    }
    protected override void OnAfterRender()
    {
        JsInterop.SetHeaderStatus();

    }
    protected void Logout()
    {
        JsInterop.RemoveToken();
        JsInterop.SetHeaderStatus();
        UriHelper.NavigateTo("/signin");
    }
}